/*
 * @Author: szx
 * @Date: 2022-05-16 13:47:33
 * @LastEditTime: 2022-05-16 13:55:09
 * @Description:
 * @FilePath: \leetcode\面试题\03\04\04.js
 */
/**
 * Initialize your data structure here.
 */
var MyQueue = function () {
    this.in = [];
    this.out = [];
};

/**
 * Push element x to the back of queue.
 * @param {number} x
 * @return {void}
 */
MyQueue.prototype.push = function (x) {
    this.in.push(x);
};

/**
 * Removes the element from in front of queue and returns that element.
 * @return {number}
 */
MyQueue.prototype.pop = function () {
    if (this.out.length) return this.out.pop();
    while (this.in.length) {
        this.out.push(this.in.pop());
    }
    return this.out.pop();
};

/**
 * Get the front element.
 * @return {number}
 */
MyQueue.prototype.peek = function () {
    if (this.out.length) return this.out[this.out.length - 1];
    while (this.in.length) {
        this.out.push(this.in.pop());
    }
    return this.out[this.out.length - 1];
};

/**
 * Returns whether the queue is empty.
 * @return {boolean}
 */
MyQueue.prototype.empty = function () {
    return !this.out.length && !this.in.length;
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * var obj = new MyQueue()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.peek()
 * var param_4 = obj.empty()
 */
